package com.ruoyi.system.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.IDashboardService;

/**
 * 首页数据统计Controller
 * 
 * @author ruoyi
 * @date 2025-01-01
 */
@RestController
@RequestMapping("/system/dashboard")
public class DashboardController extends BaseController
{
    @Autowired
    private IDashboardService dashboardService;

    /**
     * 获取统计概览数据
     */
    @GetMapping("/overview")
    public AjaxResult getOverview()
    {
        Map<String, Object> data = new HashMap<>();
        
        // 获取总数统计
        data.put("totalUsers", dashboardService.getTotalUsers());
        data.put("totalVideos", dashboardService.getTotalVideos());
        data.put("totalComments", dashboardService.getTotalComments());
        data.put("totalLikes", dashboardService.getTotalLikes());
        
        // 获取今日新增
        data.put("todayNewUsers", dashboardService.getTodayNewUsers());
        data.put("todayNewVideos", dashboardService.getTodayNewVideos());
        data.put("todayNewComments", dashboardService.getTodayNewComments());
        data.put("todayNewLikes", dashboardService.getTodayNewLikes());
        
        return success(data);
    }

    /**
     * 获取用户增长趋势（最近30天）
     */
    @GetMapping("/userTrend")
    public AjaxResult getUserTrend()
    {
        List<Map<String, Object>> trendData = dashboardService.getUserTrend(30);
        return success(trendData);
    }

    /**
     * 获取视频增长趋势（最近30天）
     */
    @GetMapping("/videoTrend")
    public AjaxResult getVideoTrend()
    {
        List<Map<String, Object>> trendData = dashboardService.getVideoTrend(30);
        return success(trendData);
    }

    /**
     * 获取视频分类统计
     */
    @GetMapping("/categoryStats")
    public AjaxResult getCategoryStats()
    {
        List<Map<String, Object>> categoryData = dashboardService.getCategoryStats();
        return success(categoryData);
    }

    /**
     * 获取用户活跃度统计（最近7天）
     */
    @GetMapping("/userActivity")
    public AjaxResult getUserActivity()
    {
        List<Map<String, Object>> activityData = dashboardService.getUserActivity(7);
        return success(activityData);
    }
}
